YOLOv5
Object Detection using YOLOv5 and OpenCV DNN in Python
Table of Content
Using openCV dnn module to run yolo5 models
Convert pytorch models to onnx model using export.py from yolo5 repository
project#
All the code and module are download from LearnOpenCV
├── coco.names
├── detect.py
├── models
│ ├── yolov5n.onnx
│ └── yolov5s.onnx
└── sample.jpg
detect code#
Warning
When use cuda, first image initialize the pipe between the cpu memory and gpu
Tip
using dnn cuda support from opencv 4.2
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
--8<-- blog/examples/open_cv/dnn/yolo5/detect.py
Run sample#
small model#
cpu#
run time: 130 ms

gpu#
run time: 39 ms
